using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using XiaoGang.Soft.XGWMS.MODEL;
using XiaoGang.Soft.XGWMS.DAL_SQL;
using XiaoGang.Soft.XGWMS.COM;

namespace XiaoGang.Soft.XGWMS.BLL
{
    public class BLL_ComProcess
    {
        private readonly DAL_ComProcess dalComprocess = new DAL_ComProcess();

        /// <summary>
        /// GetSlipID
        /// </summary>
        /// <param name="modGetID"></param>
        /// <returns></returns>
        private ReturnValue GetSlipID(MOD_M011_GET_ID modGetID)
        {
            int intNewNo = 1;
            ReturnValue returnV;
            ReturnValue returnValue = dalComprocess.Check_Exist_MaxID(modGetID.GETID_DIV, modGetID.FISCAL_YEAR);
            if (!returnValue.IsSuccess)
            {
                return returnValue;
            }
            else
            {
                if (returnValue.ResultDataSet.Tables[0].Rows.Count < 1)
                {
                    returnValue = dalComprocess.Add_GetID(modGetID);
                    if (!returnValue.IsSuccess)
                    {
                        return returnValue;
                    }
                }
                returnV = dalComprocess.Get_MaxID(modGetID.GETID_DIV, modGetID.FISCAL_YEAR);
                if (!returnV.IsSuccess)
                {
                    return returnV;
                }
                if (returnV.ResultDataSet.Tables[0].Rows.Count < 1)
                {
                    return new ReturnValue(false, "E11003");//Get SlipID Fail.
                }
                try
                {
                    intNewNo = Int32.Parse(returnV.ResultDataSet.Tables[0].Rows[0]["NEWEST_NO"].ToString());
                }
                catch
                {
                    return new ReturnValue(false, "E11003");//Get SlipID Fail.
                }
                modGetID.NEWEST_NO=intNewNo;
                returnValue = dalComprocess.Update_GetID(modGetID);
                if (!returnValue.IsSuccess)
                {
                    return returnValue;
                }
                return returnV;
            }
        }
    }
}
